package com.kuaiyin.controller.request;


import com.kuaiyin.result.Result;
import com.kuaiyin.service.ITestCaseService;
import com.kuaiyin.service.ITestPlanService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@Tag(name = "用例运行")
@RestController
@RequestMapping("/run")
public class RunController {

    @Autowired
    private ITestCaseService testCaseService;

    @Autowired
    private ITestPlanService testPlanService;

    @Operation(summary = "运行用例")
    @PostMapping("/{id}")
    public Result<String> runTestCase(@PathVariable Long id) {
        testCaseService.runTestCase(id);
        return Result.success("运行成功");
    }

    @Operation(summary = "测试计划运行")
    @PostMapping("/plan/{id}")
    public Result<String> runTestPlan(@PathVariable Long id) {
        testPlanService.runTestPlan(id);
        return Result.success("运行完成");
    }

    @Operation(summary = "停止计划运行")
    @PostMapping("/plan/stop/{id}")
    public Result<String> stopTestPlan(@PathVariable Long id) {
        testPlanService.stopTestPlan(id);
        return Result.success("停止成功");
    }

    @Operation(summary = "查看测试用例报告")
    @GetMapping("/report/case/{id}")
    public Result<Map<String, String>> reportCase(@PathVariable Long id) {
        Map<String, String> caseReportData = testCaseService.getCase(id);
        return Result.success(caseReportData);
    }
    @Operation(summary = "查看计划报告")
    @GetMapping("/report/plan/{id}")
    public Result<Map<String, String>> reportPlan(@PathVariable Long id) {
        Map<String, String> planReportData = testPlanService.getPlan(id);
        return Result.success(planReportData);
    }

}
